package org.madmatrix.glib.log;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.util.Log;

/**
 * 控制台日志
 *  
 * @author madmatrix
 */
public class ConsoleLogger implements ILogger {
	
	private String tag;
	
	private SimpleDateFormat logFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
	
	public ConsoleLogger(String tag) {
		this.tag = tag;
	}

	@Override
	public void d(String msg) {
		if (LoggerFactory.enableLogger) {
			Log.d(tag, getLogPrefix() + msg);
		}
	}

	@Override
	public void i(String msg) {
		if (LoggerFactory.enableLogger) {
			Log.i(tag, getLogPrefix() + msg);
		}
	}

	@Override
	public void w(String msg) {
		if (LoggerFactory.enableLogger) {
			Log.w(tag, getLogPrefix() + msg);
		}
	}

	@Override
	public void e(String msg) {
		if (LoggerFactory.enableLogger) {
			Log.e(tag, getLogPrefix() + msg);
		}
	}

	@Override
	public void destory() {
		logFormatter = null;
	}

	@Override
	public String getLogPrefix() {
		return "[" + logFormatter.format(new Date()) + "]";
	}

}
